#ifndef MAIN_WINDOW_H
#define MAIN_WINDOW_H

/* This header contains the class definitions of Imageview (a derived class of QGraphicsView) * 
 * and Mainwindow (also a derived class of QGraphicsView).                                    */

#include <QGraphicsView>
#include <QPushButton>

class Imageview : public QGraphicsView {

	Q_OBJECT
public:
	Imageview(QWidget *parent = 0);
	
	/* Remove everything from the scene */
	void clearScene() { scene->clear(); }

	/* Add the pixmap to the scene */
	void sceneAddPixmap(const QPixmap &pixmap) { scene->addPixmap(pixmap); }

	/* Draw a red point at the specified location */
	void drawPointAt(const int x, const int y);
	
signals:
	void pointSelected(QPoint *point);

private:
	QGraphicsScene *scene;
	QPoint selectedPoint;
	
	/* Help function for creating a QPen object */
	QPen *createPen(int w, const QColor &color);

protected:

	/* Mouse event handler */
	void mousePressEvent(QMouseEvent *event);
	void mouseMoveEvent(QMouseEvent *event);
	void mouseReleaseEvent(QMouseEvent *event);
};

class Mainwindow : public QGraphicsView {

	Q_OBJECT

public:
	Mainwindow(QWidget *parent = 0);

public slots:
	/* Slots connecting to the pushbuttons */
	void browseFile();
	void generateGradient();
	void beginIFT();
	void quit();

private slots:
	void addMousePos(QPoint *);

private:
	/* Buttons */
	QPushButton *browse;
	QPushButton *generate;
	QPushButton *start;
	QPushButton *quitapp;
	
	/* Viewing windows */
	Imageview *inputView;
	Imageview *gradientView;
	Imageview *outputView;
	
	/* Pixmaps for input image, gradient image and output image */
	QPixmap *input;
	QPixmap *gradient;
	QPixmap *output;

	/* Name of the input file */
	QString jpgFile;

	/* Array that holds mouse positions */
	int mouse_pos[100];

	/* Total number of seed pixels selected */
	int clicks;

	/* Display the image in the specified view */
	void setCurrentImage(QString img, Imageview *view, int flag);

	/* Help function to create pushbuttons */
	QPushButton *createButton(const QString &text, const char *member1 = NULL, const char *member2 = NULL);
};

#endif